package br.com.mstecsystems.mavenpoc.service;

import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import br.com.mstecsystems.mavenpoc.model.User;
import br.com.mstecsystems.mavenpoc.persistence.PersistenceException;
import br.com.mstecsystems.mavenpoc.persistence.UserDAO;

@Transactional(readOnly = true)
public class UserServiceImpl implements UserService {

	UserDAO userDAO;
	
	public UserDAO getUserDAO() {
		return userDAO;
	}

	public void setUserDAO(UserDAO userDAO) {
		this.userDAO = userDAO;
	}

	@Override
	public void addUser(User user) {
		getUserDAO().addUser(user);
	}

	@Override
	public void updateUser(User user) {
		getUserDAO().updateUser(user);
	}

	@Override
	public void deleteUser(User user) {
		getUserDAO().deleteUser(user);
	}

	@Override
	public User getUserById(int id) throws ServiceException {
		try {
			return getUserDAO().getUserById(id);
		} catch (PersistenceException e) {
			throw new ServiceException(e);
		}
	}

	@Override
	public List<User> getUsers() {
		return getUserDAO().getUsers();
	}

}
